package com.hd.service.activiti.impl;

import com.hd.dao.BaseDao;
import com.hd.entity.activiti.CommentEntity;
import com.hd.service.activiti.CommentEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.UUID;

/**
 * @Author: hzhh123
 * @Date: 2018/8/12 0:33
 */
@Service("commentEntityService")
public class CommentEntityServiceImpl implements CommentEntityService {
    @Autowired
    private BaseDao<CommentEntity,String>commentEntityBaseDao;
    @Override
    public Serializable save(CommentEntity commentEntity) {
        commentEntity.setId(UUID.randomUUID().toString());
        return commentEntityBaseDao.save(commentEntity);
    }

    @Override
    public void update(CommentEntity commentEntity) {
        commentEntityBaseDao.update(commentEntity);
    }

    @Override
    public CommentEntity get(String id) {
        return commentEntityBaseDao.get(CommentEntity.class,id);
    }

    @Override
    public List<CommentEntity> findByProcessInstanceId(String processInstanceId) {
        String hql="from CommentEntity where processInstanceId=? order by time asc";
        return commentEntityBaseDao.find(hql,processInstanceId);
    }

    @Override
    public List<CommentEntity> findComments(String processInstanceId) {
        String hql="from CommentEntity where processInstanceId=? and type=? order by time asc";
        return commentEntityBaseDao.find(hql,processInstanceId,CommentEntity.COMMENT_TYPE);
    }
    @Override
    public List<CommentEntity> findPrintComments(String processInstanceId) {
        String hql="from CommentEntity where processInstanceId=? and type=? and print=1 order by time asc";
        return commentEntityBaseDao.find(hql,processInstanceId,CommentEntity.COMMENT_TYPE);
    }

}
